package org.example.config;


import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
import lombok.RequiredArgsConstructor;
import net.sf.jsqlparser.expression.Expression;
import org.example.props.TenantProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 多租户配置中心
 */
@Configuration
//@RequiredArgsConstructor(onConstructor_ = @Autowired)
@AutoConfigureBefore(MybatisPlusConfig.class)
public class TenantConfig {

    @Autowired
    TenantProperties tenantProperties;

    /**
     * 新多租户插件配置，一缓和二缓遵循mybatis的规则
     * 需要设置MybatisConfiguration#userDeprecatedExecutor
     * 避免缓存万一出现问题
     */
    @Bean
    public TenantLineInnerInterceptor tenantLineInnerInterceptor(){
        return new TenantLineInnerInterceptor(new TenantLineHandler() {
            /**
             *  获取租户ID
             * @return
             */
            @Override
            public Expression getTenantId() {
//                String tenant =
                return null;
            }
        });
    }

}
